package operation;

import book.Book;
import book.BookList;

public class DelBook implements IOperation,IScanner{
    @Override
    public void work(BookList books) {
        System.out.println("请输入您要删除的图书名称：");
        String name=scannerName();
        //先看看书架里有没有这本书
        FindBook findBook=new FindBook();
        int index=findBook.work(name,books);
        //00:45:00
        if(index==-1){//书架上没有这本书则不需要删除
            System.out.println("书架上没有这本书，无需删除");
        }else{//书架上有这本书
            for (int i = index; i <books.getUsedSize()-1 ; i++) {
                Book temp=books.getBook(i+1);
                books.setBook(i,temp);
            }
            books.setBook(books.getUsedSize()-1,null);//他要在后一句前面
            books.setUsedSize(books.getUsedSize()-1);
            System.out.println("删除成功");
        }
    }
}